#ifndef __APP_TASK_H
#define __APP_TASK_H

#include "gd32e23x.h"
#include <stdio.h>
#include <string.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "event_groups.h"
#include "KeyCrt.h"
#include "tm1640.h"
#include "bsp_sleep.h"
#include "bsp_adc.h"
#include "valva_drive.h"
#include "output_task.h"
#include "fun_task.h"
#include "main.h"
#include "led_display.h"


#define KEY_MODE_HANDOVER           KEY_UP_K1
#define KEY_MODE_LONG_DEFAULT       KEY_LONG_K1
#define KEY_GEAR_ADD                KEY_UP_K2
#define KEY_GEAR_AUTO_ADD           KEY_REPEAT_K2
#define KEY_START_STOP              KEY_UP_K3
#define KEY_GEAR_SUBTRACT           KEY_UP_K4
#define KEY_GEAR_AUTO_SUBTRACT      KEY_REPEAT_K4
#define KEY_TIM_SET                 KEY_UP_K5    

#define KEY_POWER                   KEY_DOWN_K6


#define BREAST_PUMP_PAUSE_BIT	        ( 1 << 0 )
#define BREAST_PUMP_START_BIT	        ( 1 << 1 )
#define BREAST_BAT_CHARGE_BIT	        ( 1 << 2 )
#define BREAST_BAT_POWER_LOW_BIT	    ( 1 << 3 )
#define VALVA_STATE_EVENT_BIT	        ( 1 << 4 )
#define BREAST_TIM_SET_BIT              ( 1 << 5 )
#define BREAST_SLEEP_BIT                ( 1 << 6 )
#define BREAST_VALVE_AEROFLUXUS_BIT     ( 1 << 7)

//�?3�?状态下按键使能，其他状态下按键不使�?
#define BREAST_KEY_EN           (BREAST_TIM_SET_BIT | BREAST_PUMP_PAUSE_BIT | BREAST_PUMP_START_BIT)
//清空全部状�?
#define BREAST_SYS_ALL_BIT      (BREAST_PUMP_PAUSE_BIT | \
                                    BREAST_PUMP_START_BIT | \
                                        BREAST_BAT_CHARGE_BIT | \
                                            BREAST_BAT_POWER_LOW_BIT | \
                                                VALVA_STATE_EVENT_BIT | \
                                                    BREAST_TIM_SET_BIT)



typedef enum
{
    KNEAD_MODE = 0,     //按摩模式
    SUCKLE_MODE,        //哺乳模式
    STIMULATE_MODE,     //刺激模式
    BIONIC_MODE         //仿生模式
}mode_gather_t;

typedef enum
{
    POWER_KEY_WAKEUP = 1,
    CHARGE_WAKEUP,
    BAT_POWER_LOW_WAKEUP
}sleep_wakeup_type;


typedef enum
{   
    FIRST_GEAR = 0,     //1�?
    SECOND_GEAR,    //2�?
    THIRD_GEAR, //3�?
    FOURTH_GEAR,//4�?
    FIVETH_GEAR,//5�?
    SIXTH_GEAR,//6�?
    SEVENTH_GEAR,//7�?
    EIGHTH_GEAR,//8�?
    NINTH_GEAR//9�?
}gear_para_t;

typedef enum
{
   // BREAST_PUMP_IDLE = 0,
    BREAST_OUTPUT_INIT = 0,
    BREAST_PUMP_PAUSE ,
    BREAST_PUMP_START,
    BREAST_BAT_CHARGE,
    BREAST_BAT_POWER_LOW,
    BREAST_VALVE_AEROFLUXUS,
    BREAST_TIM_SET,
    BREAST_SLEEP
   
}task_status_t;

typedef enum
{
    CHARGE_OFF,
    CHARGE_ON
}charge_state_t;

typedef enum
{
    BAT_0,
    BAT_1,
    BAT_2,
    BAT_3
}bat_st_t;

typedef struct 
{
    uint8_t         task_tens;          //时间，十位
    uint8_t         task_units;         //时间，个位
    task_status_t   task_status;        //系统状态
    mode_gather_t   mode_gether;        //模式
    gear_para_t     suckle_gear_para;        //挡位
    gear_para_t     knead_gear_para;        //挡位
    uint16_t         task_min_set;           //任务时间
    uint16_t         tim_set_timeout;        //任务时间设置超时时间
    uint16_t        systeam_tick;           //
    bat_st_t        bat_st;                    //电池挡位
}led_packet_t;


typedef struct 
{   
    led_packet_t    packet;
    const uint16_t  *pValve_on; 
    const uint16_t  *pValve_off;
    //const uint16_t *pTog_valve_on;
   // const uint16_t *pTog_valve_off;
    const uint16_t  *pPump_start;
    const uint16_t  *pPump_tim_start;
    //const uint16_t *pPump_tim_stage_start;
    const uint16_t  *pPump_hold;
    const uint16_t  *pPump_tim_hold;
}breast_output_msg_t;

// void led_display_bat_flicker(void *data);

// void led_display_bat_powerLow(void *data);

// void led_display_pause_state(void *data);
// void led_display_timIcon_tog(void *data);
// void led_display_run_tim_set(void *data);
// void led_display_tim_set(void *data);
void app_task_init(void);
void app_task_deinit(void);
// void sys_sleep_state_set(void);
int app_send_fun_led_packet(void *data);
int app_get_ctrl_packet(void *data);
int app_get_led_packet(void *data);
EventGroupHandle_t get_evemt_handle(void);
#endif //__APP_TASK_H


